<?php
/**
 * 页面类
 * @author xun
 */
namespace Home\Controller;
class IndexController extends BaseController {
	
	private $comment_list = array();
	private $post_list = array();
	private $post_data = array();
	
    public function __construct()
    {
        parent::__construct();
        $this->assign('site_info', $this->site_info);
        $this->assign('default_info', $this->default_info);
        

        $this->comment_list = array(
        		array(
        				'comment_id' => 123,
        				'comment_time' => 223312322,
        				'content' => '美工用的，整体性能稳定，分辩率高些',
        				'is_accept' => 1,
        				'laud_count' => 3,
        				'is_laud' => 1,
        				'user_info' => array(
	        				'user_id' => 11,
	        				'nick' => '试者',
	        				'user_pic' => '/sources/pic/2.png',
        				),
        		),
        );
        
        $this->post_data = array(
        		'id' => 22,
        		'title' => '我想买台可以p图的电脑，大概五千左右',
        		'intro' => '美工用的，整体性能稳定，分辩率高些。<img src="/sources/pic/emotion/2.gif" data-innerhtml="/:8-)">',
                'like'=>11,
            	'is_like'=>1,
                'laud'=>1,
            	'is_laud'=>0,
        		'comment_count' => 1,
        		'publish_time' => 223312322,
        		'user_info' => array(
	        		'user_id' => 22,
	        		'nick' => '试者',
	        		'user_pic' => '/sources/pic/emotion/2.gif',
        		),
        );
        
        $this->post_list = array(
        		array(
	                'id'=>1,
	                'title'=>'求购电脑',
	                'intro'=>'介绍',
	                'like'=>11,
	            	'is_like'=>1,
	                'laud'=>1,
	            	'is_laud'=>0,
	                'comment_count'=>3,
	                'publish_time'=>3324221,
	        		'user_info' => array(
	        			'user_id'=> 22,
	        			'nick'=>'睡梦之龙',
	        			'user_pic'=>'/sources/pic/emotion/2.gif',
	        		),
        		),
        );
    }

    /**
     * 首页-列表
     */
    public function index()
    {
        $Index = new \Home\Model\IndexModel();
        
        $result = $Index->api_list(1, 3);
        $result = array('code'=>1, 'data'=>$this->post_list);

        if( intval($result['code'])!=1 || empty($result['data']) )
            $this->error('接口请求错误');

        $post_list = empty($result['data']) ? array() : $result['data'];

        $this->assign('post_list', $post_list);
        $this->assign('user_info', $this->getUserInfo());
        $this->display();
    }


    /**
     * 新建帖子页
     * 
     */
    public function newTrends(){
        $Http = new \Home\Model\HttpModel();
        $this->display();
    }


    /**
     * 帖子发布操作
     * 
     */
    public function releaseTrends(){
        $Http = new \Home\Model\HttpModel();
        $params['title'] = I('post.title', '', 'string');
        $params['form_article'] = I('post.form_article', '', 'string');
        //数据入库
        $this->redirect('Index/index');
    }


    /**
     * 加载编辑帖子页
     *
     */
    public function trendsRow(){
    	$Http = new \Home\Model\HttpModel();
    
    	$post_data = $this->post_data;
    	$post_data = array_merge($post_data, array('strlenth'=>mb_strlen($post_data['intro'], 'utf8')));

    	$this->failAuthRedirect($post_data['user_info']['user_id'], '权限不够','Index/index');
    
    	$this->assign('post_data', $post_data);
    	$this->assign('user_info', $this->getUserInfo());
    	$this->display();
    }

    /**
     * 编辑帖子操作
     * 
     */
    public function updateTrends(){

        $this->redirect('Index/index', array());
    }

    

    /**
     * 帖子列表页
     */
    public function trendsList(){
    	$app_id = I('post.app_id','','int');
    	$uid = I('post.uid','','int');
    	$page = I('post.page','','int');
    	

    	$this->assign('post_list', $this->post_list);
    	$this->assign('user_info', $this->getUserInfo());
    	$this->assign('other_user_info', $this->getUserInfo($uid));
    	$this->display();
    }
    
    
    
    /**
     * 某用户帖子列表页
     */
    public function otherTrendsList(){
    	$this->display();
    }


    /**
     * 添加评论-对帖子、评论的回复操作
     */
    public function addComment(){
    	$app_id = I('get.app_id', '', 'int');
    	$tid = I('get.tid', '', 'int');
    	$cid = I('get.cid', '', 'int');
    	$uid = I('get.uid', '', 'int');
    	$ruid = I('get:ruid', '', 'int');
    	$form_article = I('post.form_article', '', 'string');
    
    	//数据入库操作
    
    	$this->redirect('Index/commentlist', array('app_id'=>$app_id, 'tid'=>$tid, 'uid'=>$uid));
    }

    /**
     * 删除评论操作
     */
    
    public function deleteComment(){
    	$app_id = I('get.app_id', '', 'int');
    	$tid = I('get.tid', '', 'int');
    	$cid = I('get.cid', '', 'int');
    	$uid = I('get.uid', '', 'int');
    	$ruid = I('get:ruid', '', 'int');
    	$form_article = I('post.form_article', '', 'string');
 
    	//数据入库操作
    	 
    	$this->redirect('Index/commentlist', array('app_id'=>$app_id, 'tid'=>$tid, 'uid'=>$uid));
    }

    /**
     * 评论页
     *
     */
    public function commentView(){
    	$data = array();
    	$data['tid'] = I('get.tid', '', 'int');
    	$data['cid'] = I('get.cid', '', 'int');
    	$data['uid'] = I('get.uid', '', 'int');
    	
    	$this->assign('data', $data);
        $this->display();
    }

    
    /**
     * 帖子内容页
     * 
     */

    public function commentList(){
    	$tid = I('get.id', '', 'int');
    	
		//帖子内容页
		$post_data = $this->post_data;
		$comment_list = $this->comment_list;
		
        
        $this->assign('comment_list', $comment_list);
        $this->assign('post_data', $post_data);
        $this->assign('user_info', $this->getUserInfo());
        $this->display();

    }

    /**
     * 收藏列表页
     * 
     */

    public function collectList(){
        $Http = new \Home\Model\HttpModel();
        $this->display();

    }



    /**
     * 消息列表页
     * 
     */

    public function messageList(){
        $Http = new \Home\Model\HttpModel();


        $this->assign('user_info', $this->getUserInfo());
        $this->display();

    }




}

